package cn.iocoder.yudao.module.dlbz.controller.admin.companypayrecord;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.dlbz.controller.admin.companypayrecord.vo.*;
import cn.iocoder.yudao.module.dlbz.dal.dataobject.companypayrecord.CompanyPayRecordDO;
import cn.iocoder.yudao.module.dlbz.service.companypayrecord.CompanyPayRecordService;

@Tag(name = "管理后台 - 企业支付记录")
@RestController
@RequestMapping("/dlbz/company-pay-record")
@Validated
public class CompanyPayRecordController {

    @Resource
    private CompanyPayRecordService companyPayRecordService;

    @PostMapping("/create")
    @Operation(summary = "创建企业支付记录")
    @PreAuthorize("@ss.hasPermission('dlbz:company-pay-record:create')")
    public CommonResult<Long> createCompanyPayRecord(@Valid @RequestBody CompanyPayRecordSaveReqVO createReqVO) {
        return success(companyPayRecordService.createCompanyPayRecord(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新企业支付记录")
    @PreAuthorize("@ss.hasPermission('dlbz:company-pay-record:update')")
    public CommonResult<Boolean> updateCompanyPayRecord(@Valid @RequestBody CompanyPayRecordSaveReqVO updateReqVO) {
        companyPayRecordService.updateCompanyPayRecord(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除企业支付记录")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('dlbz:company-pay-record:delete')")
    public CommonResult<Boolean> deleteCompanyPayRecord(@RequestParam("id") Long id) {
        companyPayRecordService.deleteCompanyPayRecord(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得企业支付记录")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('dlbz:company-pay-record:query')")
    public CommonResult<CompanyPayRecordRespVO> getCompanyPayRecord(@RequestParam("id") Long id) {
        CompanyPayRecordDO companyPayRecord = companyPayRecordService.getCompanyPayRecord(id);
        return success(BeanUtils.toBean(companyPayRecord, CompanyPayRecordRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得企业支付记录分页")
    @PreAuthorize("@ss.hasPermission('dlbz:company-pay-record:query')")
    public CommonResult<PageResult<CompanyPayRecordRespVO>> getCompanyPayRecordPage(@Valid CompanyPayRecordPageReqVO pageReqVO) {
        PageResult<CompanyPayRecordDO> pageResult = companyPayRecordService.getCompanyPayRecordPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, CompanyPayRecordRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出企业支付记录 Excel")
    @PreAuthorize("@ss.hasPermission('dlbz:company-pay-record:export')")
    @OperateLog(type = EXPORT)
    public void exportCompanyPayRecordExcel(@Valid CompanyPayRecordPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<CompanyPayRecordDO> list = companyPayRecordService.getCompanyPayRecordPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "企业支付记录.xls", "数据", CompanyPayRecordRespVO.class,
                        BeanUtils.toBean(list, CompanyPayRecordRespVO.class));
    }

}